package de.tum.in.eist.poll.shared.beans;

import java.io.Serializable;


/**
 * A StudentLectureKey object is a tuple of a Student ID and a Lecture ID 
 * used as key for {@link Map}s. Using it ensures, that a Student may never
 * comment more than once on one lecture.
 *  
 * @author The EIST-POLL-21 team.
 *
 */
public class StudentLectureKey implements Comparable<StudentLectureKey>, Serializable {
	/**
	 * serialization version 
	 */
	private static final long serialVersionUID = 1L;
	
	private String studentID;
	private String lectureID;
	
	/**
	 * Dummy constructor for GWT
	 */
	public StudentLectureKey() {
		studentID = "Dummy";
		lectureID = "Dummy";
	}
	
	/**
	 * Initialize the StudentLectureKey which is a tuple with
	 * the two values.
	 * 
	 * @param studentID The Student's ID.
	 * @param lectureID The Lecture's ID.
	 */
	public StudentLectureKey(String studentID, String lectureID) {
		this.studentID = studentID;
		this.lectureID = lectureID;
	}
	
	/**
	 * @return The Student's ID
	 */
	public String getStudentID() {
		return studentID;
	}
	
	/**
	 * @return The Lecture's ID
	 */
	public String getLectureID() {
		return lectureID;
	}
	
	@Override
	public int compareTo(StudentLectureKey other) {
		if (studentID.equals(other.studentID))
			return lectureID.compareTo(other.lectureID);
		
		return studentID.compareTo(other.studentID);
	}
	
	@Override
	public boolean equals(Object other) {
		if (other instanceof StudentLectureKey) {
			StudentLectureKey otherkey = (StudentLectureKey)other;
			return studentID.equals(otherkey.studentID) && lectureID.equals(otherkey.lectureID);
		}
		return false;		
	}
	
	@Override
	public int hashCode() {
		return studentID.hashCode() + lectureID.hashCode();
	}
}